package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {

    public static HttpSession getSession(){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attributes.getRequest().getSession();
    }
    public static void setCurrentEmployee(Employee employee){
        getSession().setAttribute("EMPLOYEE_IN_SESSION",employee);
    }
    public static Employee getCurrentUser() {
        return (Employee) getSession().getAttribute("EMPLOYEE_IN_SESSION");
    }
    public static void setExpression(List<String> expressions){
        getSession().setAttribute("EXPRESS_IN_SESSION",expressions);
    }
    public static List<String> getExpression(){
        return (List<String>) getSession().getAttribute("EXPRESS_IN_SESSION");
    }
}
